export default (project, res) => {
    let start = '2040-01-01 00:00:00'
    let end = '1970-01-01 00:00:00'

    res.forEach(item => {
        if(item.planStartDate){
            if(new Date(item.planStartDate).getTime() < new Date(start).getTime()){
                start = item.planStartDate
            }

            if(new Date(item.planEndDate).getTime() > new Date(end).getTime()){
                end = item.planEndDate
            }

            item.tasks.forEach(val => {
                if(new Date(val.planStartDate).getTime() < new Date(start).getTime()){
                    start = val.planStartDate
                }

                if(new Date(val.planEndDate).getTime() > new Date(end).getTime()){
                    end = val.planEndDate
                }
            })

        }
    })
    let option = {
        title: {
            text: project.name
        },
        xAxis: {
            currentDateIndicator: true,
            min: new Date(start).getTime(),
            max: new Date(end).getTime()
        },
        series: []
    }

    let seriesItem = {
        name: project.column,
        data: []
    }

    let data = []


    res.forEach((item, index) => {
        let obj = {
            name: item.name,
            id: `task_${index}`,
            owner: item.managerName,
            // start: new Date(item.planStartDate).getTime(),
            // end: new Date(item.planEndDate).getTime(),
        }
        data.push(obj)
        item.tasks.forEach((val, ind) => {
            let subObj = {
                name: val.name,
                id: `subTask_${ind}`,
                owner: val.managerName,
                start: new Date(val.planStartDate).getTime(),
                end: new Date(val.planEndDate).getTime(),
                parent: `task_${index}`,
            }

            data.push(subObj)
        })
    })
    seriesItem.data = data
    option.series.push(seriesItem)

    return option
}